import Vue from 'vue'
import api from '../api'
Vue.use(api)
import '../utils/rem'

Vue.prototype.$imgToBase64 = img => {
    let dataURL = ''
    let canvas = document.createElement("canvas");
    let ctx = canvas.getContext("2d");
    let imgNode = new Image();
    imgNode.src = img
    imgNode.setAttribute("crossOrigin", "Anonymous");
    return new Promise(resolve => {
        imgNode.addEventListener("load", function () {
            canvas.width = imgNode.width;
            canvas.height = imgNode.height;
            ctx.drawImage(imgNode, 0, 0, imgNode.width, imgNode.height);
            dataURL = canvas.toDataURL("image/png");
            resolve('image://' + dataURL)
        })
    })
};